package com.ssy.bus.controller;

import com.ssy.bus.pojo.Department;
import com.ssy.bus.service.IDepartmentService;
import com.ssy.bus.vo.DepartmentVo;
import com.ssy.common.Constant;
import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import com.ssy.system.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @author ssy
 * <p>
 * 科室管理
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    /**
     * 分页查询
     *
     * @param departmentVo
     * @return
     */
    @GetMapping("/loadAllDepartmentByPage")
    public PageResult loadAllDepartmentByPage(DepartmentVo departmentVo, HttpSession session) {
        return this.departmentService.selectAllDepartment(departmentVo);
    }

    /**
     * 添加科室
     *
     * @param department
     * @return
     */
    @PostMapping("/addDepartment")
    public Result addDepartment(@RequestBody Department department) {
        department.setRegister(0);
        department.setCreateTime(new Date());
        return this.departmentService.addDepartment(department);
    }

    /**
     * 删除科室
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteDepartment/{id}")
    public Result deleteDepartment(@PathVariable Integer id) {
        return this.departmentService.deleteDepartmentById(id);
    }

    /**
     * 批量删除科室
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDepartment/{ids}")
    public Result bathDepartment(@PathVariable Integer[] ids) {
        return this.departmentService.bathDepartment(ids);
    }

    /**
     * 修改科室
     *
     * @param department
     * @return
     */
    @PostMapping("/updateDepartment")
    public Result updateDepartment(@RequestBody Department department) {
        return this.departmentService.updateDepartmentById(department);
    }

    /**
     * 修改科室状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateDepartmentState/{id}/{state}")
    public Result updateDepartmentState(@PathVariable Integer id, @PathVariable Integer state) {
        Department department = new Department();
        department.setId(id);
        department.setState(state);
        return this.departmentService.updateDepartmentById(department);
    }

    /**
     * 加载所有科室
     *
     * @return
     */
    @GetMapping("/loadAllDepartment")
    public Result loadAllDepartment() {
        return this.departmentService.LoadAllDepartment();
    }
}
